package com.bcsq.todolistdemo.demo.activity;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.bcsq.todolistdemo.R;


public class ToDoListActivity extends AppCompatActivity {

    Toolbar toolbar;
    String groupName;
    Context mContext;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_to_do_list);
        Intent intent = getIntent();
        groupName = intent.getStringExtra("groupName");

        init();
    }


    private void init() {
        mContext = this;
        toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle(groupName);
        toolbar.setLogo(R.mipmap.ic_launcher);
        setSupportActionBar(toolbar);

    }

    //菜单
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //将菜单注入
        getMenuInflater().inflate(R.menu.menu_add, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();
        switch (itemId){
            case R.id.item_add :
                Intent intent = new Intent(mContext, AddToDoActivity.class);
                startActivity(intent);
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
